package com.lqk.fnandroid

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.detectTransformGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import com.lqk.fnandroid.res.FNAndroidTheme

const val TAG = "MainComposeActivity"

class MainComposeActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        enableEdgeToEdge()
        super.onCreate(savedInstanceState)
        setContent {
            FNAndroidTheme {
                Greeting("Android Compose")
            }
        }
    }
}

@Composable
fun ComposeSurfaceView() {
    Box(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.Gray)
            .pointerInput(Unit) {
                // 点击事件
                detectTapGestures (
                    onTap = {
                        Log.d(TAG, "ComposeSurfaceView: onTap")
                    },
                    onDoubleTap = {
                        Log.d(TAG, "ComposeSurfaceView: onDoubleTap")
                    },
                    onLongPress = {
                        Log.d(TAG, "ComposeSurfaceView: onLongPress")
                    },
                    onPress = {
                        Log.d(TAG, "ComposeSurfaceView: onPress")
                    }
                )
            }
            .pointerInput(Unit) {
                detectDragGestures { change, dragAmount ->
                    Log.d(TAG, "ComposeSurfaceView: Drag")
                }
            }
            .pointerInput(Unit) {
                // move 事件
                detectTransformGestures { centroid, pan, zoom, rotation ->
                    Log.d(TAG, "ComposeSurfaceView: Transform")
                }
            },
    ) {
//        AndroidView(
//            modifier = Modifier
//                .fillMaxSize()
//                .clip(RoundedCornerShape(0)),
//            factory = {
//                CustomGLSurfaceView(it)
//            },
//            update = {}
//        )
    }
}

@Composable
fun Greeting(name: String) {
    val context = LocalContext.current
    Log.d(TAG, "Greeting: ${LocalConfiguration.current.screenWidthDp}")
    Log.d(TAG, "Greeting: ${LocalConfiguration.current.screenHeightDp}")
    Log.d(TAG, "Greeting: ${LocalConfiguration.current.fontScale}")
    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.White)
            .systemBarsPadding()
    ) {
        ComposeSurfaceView()
    }
}